package com.zmj.sy.mom.srv.aps.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zmj.sy.mom.srv.aps.bean.entity.lantekpre.LantekPushPackage;
import com.zmj.sy.mom.srv.aps.bean.vo.report.ReportPreNestErrResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.report.ReportPreNestInfoNewResVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LantekPushPackageMapper extends SyMapper<LantekPushPackage> {

    @Select("SELECT pp.pre_nest_code AS preNestCode, ppl.plate_length AS standardPlateLength, ppl.plate_width AS standardPlateWidth, npl.texture AS texture, " +
            "npl.norm AS thickness, COUNT( DISTINCT npl.stock_list_no ) AS planAmount, SUM( npa.net_weight * npa.quantity ) AS partWeight, AVG(npl.rate) AS rate, ps.plate_rate AS standardRate " +
            "FROM tb_third_lantek_push_package pp LEFT JOIN tb_third_lantek_push_plan ppl ON pp.pre_nest_code = ppl.product_id LEFT JOIN tb_third_lantek_nest_part npa ON ppl.nest_plan_id = npa.nest_plan_id " +
            "AND ppl.pre_version = npa.pre_version LEFT JOIN tb_third_lantek_nest_plate npl ON npa.nest_id = npl.nest_id AND npa.pre_version = npl.pre_version LEFT JOIN tb_order o ON o.id = pp.order_id " +
//            "LEFT JOIN tb_third_lantek_nest_excess ne ON npl.nest_id = ne.nest_id AND npl.pre_version = ne.pre_version " +
            "LEFT JOIN tb_base_plate_standard ps ON npl.texture = ps.texture AND npl.norm = ps.height " +
            " ${ew.customSqlSegment} ")
    List<ReportPreNestInfoNewResVo> preNestReport(@Param(Constants.WRAPPER) QueryWrapper<LantekPushPackage> qw);

    @Select("SELECT p.id AS id, p.component_id AS parPlmId, p.part_id AS plmId, p.part_name AS materName, d.error_msg AS errInfo " +
            "FROM tb_third_lantek_push_package pp INNER JOIN tb_third_lantek_push_plan p ON pp.pre_nest_code = p.product_id " +
            "INNER JOIN tb_third_lantek_push_draw d ON p.part_id = d.part_id " +
            " ${ew.customSqlSegment} ")
    List<ReportPreNestErrResVo> preNestException(@Param(Constants.WRAPPER) QueryWrapper<LantekPushPackage> qw);

}
